const { DataTypes } = require("sequelize");
const sequelize = require("../db");
const User = require("./user.model");

const ApiList = sequelize.define(
    "ApiList",
    {
        projectName: {
            type: DataTypes.STRING,
            allowNull: false,
        },
        interfaceName: {
            type: DataTypes.STRING,
            allowNull: false,
        },
        description: {
            type: DataTypes.TEXT,
            allowNull: false,
        },
        fileUrls: {
            type: DataTypes.JSON,
            allowNull: true,
        },
        status: {
            type: DataTypes.STRING,
            allowNull: false,
            defaultValue: "dev",
        },
        version: {
            type: DataTypes.STRING,
            allowNull: false,
        },
        userId: {
            type: DataTypes.INTEGER,
            allowNull: false,
            references: {
                model: User,
                key: "id",
            },
        },
    },
    {
        timestamps: true,
    }
);

// 一个用户可以创建多个 API 列表
ApiList.belongsTo(User, { foreignKey: "userId", as: "creator" });

module.exports = ApiList;
